<template>
	<view class="" style="width: 100vw;min-height: 100vh;background:#F9F9F9;">
		<view class="" style="position: relative;">
			<hx-navbar title="我的奖品" :back="true"  :color="kblackColor" :fixedWhiteStyle="true" :fixed="false" rightIcon="help" barPlaceholder="hidden" transparent="auto" @clickright="hintClick(1,1)"></hx-navbar>
		</view>
		<view class="container" style="background:#F9F9F9;">
			<view class="content-list">
				<view class="item" v-if="item.prizesType==2 || item.prizesType==3" v-for="(item,index) in list">
					<view class="left">
						<view v-if='item.prizesType==2' class="left-bg bg-blue"></view>
						<view v-if='item.prizesType==3' class="left-bg bg-purple"></view>
						<view class="top-circle"></view>
						<view class="bottom-circle"></view>
						<!-- 奖品类型 1->虚拟奖品 2->实物奖品 3->盲盒奖品 -->
						<view class="title" v-if='item.prizesType==2'>¥{{item.equivalence}}</view>
						<view class="title" style="	font-size: 40rpx;" v-if='item.prizesType==3'>1次</view>
					</view>
					<view class="right">
						<view v-if='item.prizesType==2' class="text">京东E卡</view>
						<view v-else class="text" v-if='item.prizesType==3'>盲盒抽奖券</view>
						<view v-if='item.prizesType==2 && item.status==1' @click="hintClick(2,item)"
							class="use-btn bg-blue">
							 查看兑换码
							</view>
						<view v-if='item.prizesType==2 && item.status==2' style="color: #000;" class="use-btn bg-gray">
							已使用</view>
						<view v-if='item.prizesType==3 && item.status==1' @click="hintClick(3,item)"
							class="use-btn bg-purple">立即使用</view>
						<view v-if='item.prizesType==3 && item.status==2' style="color: #000;" class="use-btn bg-gray">
							已使用</view>
					</view>
				</view>
			</view>
		</view>
		<view class="none_box" v-if="list.length == 0">
			<image src="@/static/without.png" mode="widthFix"></image>
		</view>
		<uni-popup ref="confirmpop">
			<view class="alert_container">
				<!-- 提示 -->
				<view class="" v-if="popUpType==1">
					<view class="" style="text-align: right;">
						<image src="@/static/ai/close.png" @click="hintClose()" class="popicon" mode="widthFix"></image>
					</view>
					<view class="alert_cont">
						我的奖品只展示您所获得的京东E卡和钻石抽奖券。空投奖励请在在金世界我的馆藏中查看。
					</view>
				</view>
				<view class="popUpType2" v-if="popUpType==2">
					<view class="popname">
						兑换码
					</view>
					<view class="popCardNumber">
						{{cardNumber}}
					</view>
					<view>
						<view style="margin: 20rpx auto;" @click="duplicateClick()" class="use-btn bg-blue">复制</view>
					</view>
				</view>
				<view class="popUpType3" v-if="popUpType==3">
					<view class="popImage">
						<image src="@/static/aipicture/award.png" style="width: 345rpx;height: 200rpx;"></image>
					</view>
					<view class="popCardNumber">
						恭喜您成功抽中了{{credits}}个灵感，
						快去你的灵感记录查看吧!
					</view>
					<view>
						<view @click="hintClose()" style="margin: 30rpx auto;" class="use-btn bg-purple">开心收下</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				popUpType: 1,
				list: [],
				cardNumber: '', //兑奖码
				credits: '' //灵感
			}
		},
		onLoad() {

		},
		onReachBottom() {},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onLoad() {
			this.getList()
		},
		methods: {
			//列表
			getList() {
				this.$api.aiPrizesList(res => {
					if (res.status) {
						this.list = res.data.data
					}
				})
			},
			//复制
			duplicateClick() {
				uni.setClipboardData({
					data: this.cardNumber,
					success: () => {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						});
					},
					fail: (err) => {
						console.error('复制失败', err);
					}
				});
			},
			// 提示
			hintClick(index, val) {
				this.popUpType = index
				if (index == 2 || index == 3) {
					var data = {
						id: val.id,
						prizesType: val.prizesType
					}
					this.$api.aiPrizesGrant(data, res => {
						if (res.status) {
							this.cardNumber = res.data.data.cardNumber
							this.credits = res.data.data.credits
							this.getList()
						}

					})
				}

				this.$refs.confirmpop.open()
			},
			hintClose() {
				this.$refs.confirmpop.close()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 40rpx;
	}

	.bg-blue {
		background: linear-gradient(135deg, #58A2D5 0%, #5678D7 100%);
	}

	.bg-purple {
		background: linear-gradient(135deg, #6C58D5 0%, #AA56D7 100%);
	}

	.content-list {
		width: 100%;
		display: flex;
		flex-direction: column;

		.item {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 20rpx;
			border-radius: 20rpx;
			height: 180rpx;
			overflow: hidden;
			background: #FFFFFF;



			.bg-gray {
				color: #000;
				background: #E5E5E5;
			}

			.left {
				display: flex;
				flex-direction: row;

				.left-bg {
					width: 160rpx;
				}

				.top-circle {
					margin-left: -20rpx;
					;
					margin-top: -20rpx;
					width: 40rpx;
					height: 40rpx;
					border-radius: 20rpx;
					background: #F9F9F9;
				}

				.bottom-circle {
					margin-top: 160rpx;
					margin-left: -40rpx;
					;
					margin-bottom: -20rpx;
					width: 40rpx;
					height: 40rpx;
					border-radius: 20rpx;
					background: #F9F9F9;
				}

				.title {
					position: absolute;
					color: #FFFFFF;
				
					width: 160rpx;
					height: 180rpx;
					padding-top: 60rpx;
					text-align: center;
				}
			}

			.right {
				display: flex;
				flex-direction: column;

				.text {
					margin: 0 20rpx 0rpx 20rpx;
					color: #010101;
					font-size: 28rpx;
				}


			}
		}
	}

	.use-btn {
		margin: 10rpx 20rpx 20rpx 20rpx;
		color: white;
		width: 180rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 28rpx;
		border-radius: 30rpx;
		text-align: center;
	}

	.alert_container {
		width: 687rpx;
		background-size: contain;
		padding-top: 10rpx;
		background-clip: padding-box, border-box;
		background-origin: padding-box, border-box;
		border-radius: 20rpx;
		border: 5rpx solid transparent;
		background-image: linear-gradient(to bottom, #ffffff, #ffffff), linear-gradient(0deg, #7776FF, #AE2CF1);

		.popicon {
			width: 26rpx;
			text-align: right;
			margin: 20rpx;
		}

		.alert_cont {
			width: 577rpx;
			font-weight: 500;
			font-size: 25rpx;
			color: #000000;
			margin: 60rpx auto 110rpx;
		}

		.popUpType2 {
			width: 630rpx;
			margin: 30rpx auto;

			.popname {
			text-align: center;
				font-size: 28rpx;
				color: #000000;
			}

			.popCardNumber {
				height: 100rpx;
				line-height: 100rpx;
				font-size: 32rpx;
				font-weight: 600;
				text-align: center;
			}
		}

		.popUpType3 {
			.popImage {
				text-align: center;
				margin: 20rpx auto;
			}

			.popCardNumber {
				font-weight: 500;
				font-size: 24rpx;
				color: #000000;
				margin: 20rpx auto;
				width: 360rpx;
			}
		}

	}

	.none_box {
		width: 534rpx;
		margin: 117rpx auto;
		font-size: 32rpx;
		color: #ABA9B4;
	}

	.none_box image {
		width: 100%;
		height: 534rpx;
		margin-bottom: 10rpx;
	}
</style>